<?php
declare(strict_types=1);

namespace App\Resource\Activity\MidAutumn2022\Task;


use App\Models\MainDB\MallProducts;
use Illuminate\Http\Resources\Json\JsonResource;

class RewardResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            "id" => $this->id,
            "count" => $this->count,
            "stocks" => $this->reward->prize_type == MallProducts::RELATION_TYPE ? floor($this->stocks / $this->count) : $this->stocks,
            "reward_id" => $this->reward_id,
            "status" => $this->status,
            "prize" => [
                "id" => $this->reward->prize_id,
                "type" => $this->reward->prize_type,
                "name" => $this->reward->prize_type == MallProducts::RELATION_TYPE ? $this->reward->prize->title : $this->reward->prize->name,
                "image" => $this->reward->prize->picture,
                "coin" => $this->reward->prize_type == MallProducts::RELATION_TYPE ? 0 : $this->reward->prize->price,
            ],

        ];
    }
}